package com.bakabase.utils;

import java.util.Random;

/**
 * 字符串工具类
 */
public class RandomCharUtils {

    // 定义包含大小写字母和数字的字符集
    private static final String CHARACTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

    // 创建随机数生成器实例
    private static final Random RANDOM = new Random();

    private static final int charLength = 11;

    /**
     * 生成指定长度的随机字符串
     *
     * @return 随机生成的字符串
     */
    public static String generateRandomString() {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < charLength; i++) {
            // 生成一个随机索引
            int index = RANDOM.nextInt(CHARACTERS.length());
            // 使用索引从字符集获取字符，并拼接到StringBuilder中
            sb.append(CHARACTERS.charAt(index));
        }
        return sb.toString();
    }
}
